home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AEWIN100.ARJ / VIDBUF.H < prev    next >
C/C++ Source or Header  |  1991-10-28  |  3KB  |  116 lines

  1. /**********************************************************************
  2.  *  
  3.  *  NAME:           vidbuf.h
  4.  *  
  5.  *  DESCRIPTION:    video buffer class
  6.  *  
  7.  *  copyright (c) 1990 J. Alan Eldridge
  8.  * 
  9.  *  M O D I F I C A T I O N   H I S T O R Y
  10.  *
  11.  *  when        who                 what
  12.  *  -------------------------------------------------------------------
  13.  *  11/09/90    J. Alan Eldridge    created
  14.  *  
  15.  *********************************************************************/
  16.  
  17. #ifndef __VIDBUF_H
  18. #define __VIDBUF_H
  19.  
  20. //  buffer for screen image
  21.  
  22. class vidbuf;   //  establish the name
  23. extern vidbuf   Screen;
  24.  
  25. class vidbuf {
  26.  
  27. protected:
  28.  
  29.     int     state;      //  OK, ERR
  30.     int     rows,       //  dimensions
  31.             cols;
  32.     int     yOrg,       //  origin on screen
  33.             xOrg;
  34.     int     yCur,       //  cursor position
  35.             xCur;     
  36.     vidchr  *pbuf;      //  buffer for image
  37.  
  38.     //  get ptr to vidchr at row,col
  39.     vidchr  *vidptr(int r, int c)
  40.         { return &pbuf[r*cols+c]; }
  41.         
  42.     //  update to display screen
  43.  
  44.     void    display(int row, int col, int cnt, int vflag = 1);
  45.     void    setcursor(int vflag = 1);
  46.  
  47.     //  clear a range of a line to a value
  48.     void    clrline(int r, int left, int right, int chr, int att);
  49.     
  50.     //  clear a rectangular area to a value
  51.     void    clear(int yul, int xul, int ylr, int xlr, int chr, int att);
  52.  
  53.     //  write one character/attribute
  54.     void    putchr(int row, int col, int chr, int att)
  55.         { vidptr(row, col)->put(chr, att); }
  56.  
  57. public:
  58.  
  59.     //  get status
  60.     int status()    { return  state; }
  61.     
  62.     //  get size, position info
  63.     void    getul(int &y, int &x)
  64.         { y = yOrg; x = xOrg; }
  65.     void    getlr(int &y, int &x)
  66.         { y = yOrg + rows - 1; x = xOrg + cols - 1; }
  67.     void    getmaxrc(int &y, int &x)
  68.         { y = rows-1; x = cols-1; }
  69.         
  70.     //  set up buffer, etc.
  71.     void    open(int yUl, int xUl, int yLr, int xLr);
  72.  
  73.     //  free memory, etc;
  74.     void    close();
  75.     
  76.     //  constructor
  77.     vidbuf()        { state = ERR; };
  78.     vidbuf(int yUl, int xUl, int yLr, int xLr)
  79.         { open(yUl, xUl, yLr, xLr); }
  80.     
  81.     //  destructor
  82.     ~vidbuf()       { close(); }
  83.         
  84.     //  clear a rectangular area to a value
  85.     void    clear()
  86.         { clear(0, 0, rows - 1, cols - 1, ' ', vid_defaultatt); }
  87.  
  88.     //  set cursor position
  89.     //  these are virtual because a window is derived from
  90.     //  a vidbuf, and has additional stuff to do here
  91.     virtual void    setpos(int y, int x)
  92.         { yCur = y; xCur = x; }
  93.     virtual void    getpos(int &y, int &x)
  94.         { y = yCur; x = xCur; }
  95.         
  96.     //  update to display screen
  97.     //  this is virtual because a vidbuf only knows how to
  98.     //  refresh the entire image; a window has a "dirty
  99.     //  region" and can do a smart refresh
  100.     virtual void    refresh(int vflag = 1);
  101.  
  102.     // read/write from/to array of video chars
  103.     void    write(int atrow, int atcol, vidchr *pvc, int cnt)
  104.         { memcpy(vidptr(atrow,atcol), pvc, cnt*sizeof(vidchr)); }
  105.     void    read(int atrow, int atcol, vidchr *pvc, int cnt)
  106.         { memcpy(pvc, vidptr(atrow,atcol), cnt*sizeof(vidchr)); }
  107.  
  108.     //  copy from the Screen video buffer
  109.     void    cpscreen();
  110.         
  111.     //  check if pointing device is in window
  112.     int     inwindow(int &y, int &x);
  113. };
  114.  
  115. #endif
  116.